#coding:utf-8
__author__ = '自之梦'

"""
@author:自之梦
@time: 17/5/25 上午10:26

#运单信息通知接口
"""
import random
import time

def Ma5_Val(str, val_type=""):
    #MD5加密
    import hashlib
    import types
    if type(str) is types.StringType:
        md5 = hashlib.md5()
        md5.update(str)
        if val_type == "upper":
            return md5.hexdigest().upper()
        else:
            return md5.hexdigest()
    else:
        return "errorCode: parameter1 must be str "

def Data_Key_Sort(data):
    #字典key排序
    result=sorted(data.items(), key=lambda item:item[0])
    test=""
    for i in result:
        test = test+ "".join(i)
    return test

def Key_Val_Sort(data):
    #字典key排序
    result=sorted(data.items(), key=lambda item:item[0])
    test = []
    for i in result:
        result = "=".join(i)
        test.append(result)

    return "&".join(test)



if __name__ =="__main__":

    test='123456customerIdLJJ-Tformatjsonmethodshop.delivery.order.createsign_methodmd5timestamp2017-08-23 15:03:09v1.0\
{"shopCode": "XZQN", "takeTime": "2017-08-23 15:03:09", \
"orderLines": [{"barcode": "6937004403039", "customBc": "6937004403039", "quantity": "6"}\
,{"barcode": "6937004403039", "customBc": "6937004403039", "quantity": "6"}\
,{"barcode": "jittest_001", "customBc": "jittest_001", "quantity": "6"}\
],"totalCount": 66, "category_count": 1, "deliveryOrderCode": "X001"}123456'
    result =Ma5_Val(test,"upper")

    print result


"""
['data_digest: 7eva%2FWU9u9JY%2FXP4UFOi%2FA%3D%3D',
'logistics_interface: %3CItemInfoQueryRequestDown%3E%3Ccheckword%3Echeckword%3C%2Fcheckword%3E%3CserialNumber%3E00001%3C%2FserialNumber%3E%3CwarehouseCompanyCode%3ELCSFPZ%3C%2FwarehouseCompanyCode%3E%3CcompanyCode%3EALOG%3C%2FcompanyCode%3E%3CpageIndex%3E1%3C%2FpageIndex%3E%3CitemCodeList%3E%3CitemCode%3E%3C%2FitemCode%3E%3C%2FitemCodeList%3E%3C%2FItemInfoQueryRequestDown%3E']



data={"name":"lili","age":"23","sex":"1"}
    result=sorted(data.items(), key=lambda item:item[0])
    test=""
    for i in result:
        test = test+ "".join(i)
    print test

"""
